﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;
using System.Runtime.InteropServices;

namespace HandRise.MBHOP.Controls
{
    public class MessageDialog : Component
    {
        /// <summary>
        /// 对话框类型

        /// </summary>
        public DialogType ButtonType
        {
            get
            {
                return dialogForm.ButtonType;
            }
            set
            {
                dialogForm.ButtonType = value;
            }
        }

        /// <summary>
        /// 背景色

        /// </summary>
        public Color BackColor
        {
            get
            {
                return dialogForm.BackColor;
            }
            set
            {
                dialogForm.BackColor = value;
            }
        }
        /// <summary>
        /// 文本居上边框的距离

        /// </summary>
        [DefaultValue(10)]
        public int TextTopSpace
        {
            get
            {
                return dialogForm.TextTopSpace;
            }
            set
            {
                dialogForm.TextTopSpace = value;
            }
        }

        /// <summary>
        /// 要显示的文本
        /// </summary>
        public string MessageText
        {
            get
            {
                return dialogForm.MessageText;
            }
            set
            {
                dialogForm.MessageText = value;
            }
        }

        /// <summary>
        /// 第一个按钮的坐标
        /// </summary>
        public Point ButtonLocation1
        {
            get
            {
                return dialogForm.ButtonLocation1;
            }
            set
            {
                dialogForm.ButtonLocation1 = value;
                dialogForm.isDefaultLocation1 = false;
            }
        }

        /// <summary>
        /// 第二个按钮的坐标
        /// </summary>
        public Point ButtonLocation2
        {
            get
            {
                return dialogForm.ButtonLocation2;
            }
            set
            {
                dialogForm.ButtonLocation2 = value;
                dialogForm.isDefaultLocation2 = false;
            }
        }

        /// <summary>
        /// 第一个按钮弹起时的图片

        /// </summary>
        public Image ButtonUpBackground1
        {
            get
            {
                return dialogForm.ButtonUpBackground1;
            }
            set
            {
                dialogForm.ButtonUpBackground1 = value;
            }
        }

        /// <summary>
        /// 第二个按钮弹起时的图片

        /// </summary>
        public Image ButtonUpBackground2
        {
            get
            {
                return dialogForm.ButtonUpBackground2;
            }
            set
            {
                dialogForm.ButtonUpBackground2 = value;
            }
        }

        /// <summary>
        /// 第一个按钮按下时的图片

        /// </summary>
        public Image ButtonDownBackground1
        {
            get
            {
                return dialogForm.ButtonDownBackground1;
            }
            set
            {
                dialogForm.ButtonDownBackground1 = value;
            }
        }

        /// <summary>
        /// 第二个按钮按下时的图片

        /// </summary>
        public Image ButtonDownBackground2
        {
            get
            {
                return dialogForm.ButtonDownBackground2;
            }
            set
            {
                dialogForm.ButtonDownBackground2 = value;
            }
        }

        /// <summary>
        /// 第一个按钮的文字
        /// </summary>
        [DefaultValue("是")]
        public string ButtonText1
        {
            get
            {
                return dialogForm.ButtonText1;
            }
            set
            {
                dialogForm.ButtonText1 = value;
            }
        }

        /// <summary>
        /// 第二个按钮的文字
        /// </summary>
        [DefaultValue("否")]
        public string ButtonText2
        {
            get
            {
                return dialogForm.ButtonText2;
            }
            set
            {
                dialogForm.ButtonText2 = value;
            }
        }

        /// <summary>
        /// 按钮的尺寸

        /// </summary>
        //[DefaultValue(new Size(60, 25))]
        public Size ButtonSize
        {
            get
            {
                return dialogForm.ButtonSize;
            }
            set
            {
                dialogForm.ButtonSize = value;
                dialogForm.isDefaultSize = false;
            }
        }

        /// <summary>
        /// 对话框的背景图

        /// </summary>
        public Image Background
        {
            get
            {
                return dialogForm.Background;
            }
            set
            {
                dialogForm.Background = value;

            }
        }

        DialogForm dialogForm = new DialogForm();

        public MessageDialogResult ShowDialog(Form parentForm, string msgText, DialogType buttonType)
        {
            dialogForm.MessageText = msgText;
            return ShowDialog(parentForm, buttonType);
        }

        public MessageDialogResult ShowDialog(Form parentForm, DialogType buttonType)
        {
            this.ButtonType = buttonType;

            if (parentForm.WindowState == FormWindowState.Maximized)
                dialogForm.Text = "";
            else
            {
                dialogForm.WindowState = parentForm.WindowState;
                //dialogForm.ControlBox = parentForm.ControlBox;
                dialogForm.MaximizeBox = parentForm.MaximizeBox;
                dialogForm.Text = parentForm.Text;
            }

            if (dialogForm.ShowDialog() == DialogResult.Yes)
            {
                return MessageDialogResult.Button1;
            }
            else
            {
                return MessageDialogResult.Button2;
            }
        }
        public MessageDialogResult ShowDialog(Form parentForm, DialogType buttonType, EventHandler eventHandler)
        {
            this.ButtonType = buttonType;
            if (parentForm.WindowState == FormWindowState.Maximized)
            {
                this.dialogForm.Text = "";
            }
            else
            {
                this.dialogForm.WindowState = parentForm.WindowState;
                this.dialogForm.MaximizeBox = parentForm.MaximizeBox;
                this.dialogForm.Text = parentForm.Text;
            }
            if (eventHandler == null)
            {
                if (this.dialogForm.ShowDialog() == DialogResult.Yes)
                {
                    parentForm = null;
                    return MessageDialogResult.Button1;
                }
                parentForm = null;
                return MessageDialogResult.Button2;
            }
            if (this.dialogForm.ShowDialog(parentForm, eventHandler) == DialogResult.Yes)
            {
                parentForm = null;
                return MessageDialogResult.Button1;
            }
            parentForm = null;
            return MessageDialogResult.Button2;
        }




        public MessageDialogResult ShowDialog(Form parentForm, string msgText, DialogType buttonType, EventHandler eventHandler)
        {
            this.dialogForm.MessageText = msgText;
            return this.ShowDialog(parentForm, buttonType, eventHandler);
        }

 

 


    }
}
